package com.zjl.legendary.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zjl.legendary.dao.QuestionDao;
import com.zjl.legendary.entity.Question;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoujingluo
 * @date 2021/5/28 11:11
 */
public class QuestionReadListener extends AnalysisEventListener<Question> {
    private QuestionDao questionDao;

    private List<Question> list = new ArrayList<>();
    private Integer uid;

    @Override
    public void invoke(Question question, AnalysisContext analysisContext) {
        question.setUid(uid);
        list.add(question);
        System.out.println(question);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println(questionDao.insertBatch(list));
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public Integer getUid() {
        return uid;
    }

    public QuestionDao getQuestionDao() {
        return questionDao;
    }

    public void setQuestionDao(QuestionDao questionDao) {
        this.questionDao = questionDao;
    }
}
